package 设计模式.单例模式;

/*****
 * @Author: http://www.itheima.com
 * @Description: com.itheima.singleton.SingleModel
 ****/
public class SingleModel {

    //整个应用程序中只有一个自己的实例
    private static SingleModel singleModel;

    //只能自己创建自己
    private SingleModel() {
    }

    //需要提供一个方法让外界调用获取实例
    public static SingleModel getInstance(){
        if(singleModel==null){
            //如果singlemodel为空，则创建对象实例
            synchronized (SingleModel.class){
                if(singleModel==null){
                    singleModel = new SingleModel();
                }
            }
        }
        return singleModel;
    }
}
